package com.zzccyy.jpdemo.utils;


import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zzccyy.jpdemo.R;
import com.zzccyy.jpdemo.bean.DateInfo;


public class DayAdapter extends BaseQuickAdapter<DateInfo, BaseViewHolder> {


    public DayAdapter(int layoutResId) {
        super(layoutResId);

    }


    @Override
    protected void convert(BaseViewHolder helper, DateInfo item) {
        TextView tvDay1 = helper.getView(R.id.tvDay1);
        TextView tvDay2 = helper.getView(R.id.tvDay2);

        String s = extractMonthAndDay(item.chineseDate);
        tvDay1.setText(item.weekDay);
        if (s.length()==4){
            String substring = s.substring(0, 2);
            String substring1 = s.substring(2, 4);
            tvDay2.setText(substring+"-"+substring1);
        }
        tvDay1.setTextColor(item.isSelect ? ContextCompat.getColor(mContext,R.color.color_5a79ff) :ContextCompat.getColor(mContext,R.color.color_ffffff));
        tvDay2.setTextColor(item.isSelect ?ContextCompat.getColor(mContext,R.color.color_5a79ff):ContextCompat.getColor(mContext,R.color.color_ffffff));
        helper.itemView.setBackgroundResource(item.isSelect ?R.drawable.bg_ffffff_c15:R.drawable.bg_dfffffff_c15);
    }
    public static String extractMonthAndDay(String chineseDate) {
        // 使用正则表达式分割字符串
        String[] parts = chineseDate.split("[年月日]");

        // 提取月份和日期
        String month = parts[1].trim();
        String day = parts[2].trim();

        // 格式化为两位数
        String formattedMonth = String.format("%02d", Integer.parseInt(month));
        String formattedDay = String.format("%02d", Integer.parseInt(day));

        // 组合结果
        return formattedMonth + formattedDay;
    }
}

